package com.study.samsung.Control.htControl;

import com.study.samsung.Entity.Classification;
import com.study.samsung.Entity.Succession;
import com.study.samsung.Service.ClassificationService;
import com.study.samsung.Service.SuccessionService;
import com.study.samsung.Utils.BaseServlet;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@WebServlet("/goodscategory")
public class GoodsCategoryServlet extends BaseServlet {
    ClassificationService cs = new ClassificationService();
    SuccessionService ss = new SuccessionService();
    @Override
    public String excute(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Object obj = session.getAttribute("admin");
        if (obj==null){
            return "f:htjsp/login";
        }else {
            request.setCharacterEncoding("utf-8");
            List<Classification> classifications = cs.selectAll();
            session.setAttribute("classifications",classifications);
            List<Succession> successions = ss.selectAll();
            session.setAttribute("successions",successions);
            return "f:htjsp/goodscategory";
        }

    }

    public String categoryadd(HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setCharacterEncoding("utf-8");
        return "f:htjsp/goodscategoryadd";
    }

    public String categoryaddone(HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setCharacterEncoding("utf-8");
        return "f:htjsp/goodscategoryaddone";
    }

    public Integer categorydel(HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setCharacterEncoding("utf-8");
        String lid = request.getParameter("id");
        int i = Integer.parseInt(lid);
        Integer deladdcategory = cs.deladdcategory(i);
        return deladdcategory;
    }

    public Integer categorydelone(HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setCharacterEncoding("utf-8");
        String lid = request.getParameter("id");
        int i = Integer.parseInt(lid);
        Integer deladdcategory = ss.deladdcategory(i);
        return deladdcategory;
    }
}
